/**
 * @param {Egg.Application} app - egg application
 */
module.exports = (app) => {
  const { router, controller, middleware } = app;
  router.prefix("/api/v1");
  const auth = middleware.auth();

  // user 用户相关
  router.post("/users", controller.user.create); // 注册
  router.post("/users/login", controller.user.login); // 登录
  router.get("/users", auth, controller.user.getCurrentUser); // 登录用户信息
  router.patch("/users", auth, controller.user.update); // 更新用户
  router.get(
    // 用户信息
    "/users/:userId",
    middleware.auth({ requried: false }),
    controller.user.getUser
  );

  // subscription 用户订阅
  router.post("/users/:userId/subscribe", auth, controller.user.subscribe); // 订阅
  router.delete("/users/:userId/subscribe", auth, controller.user.unsubscribe); // 取消订阅
  router.get("/users/:userId/subscriptions", controller.user.getSubscriptions); // 获取订阅消息

  // 阿里云 VOD
  router.get("/vod/createUploadVideo", auth, controller.vod.createUploadVideo); // 上传视频
  router.get(
    // 更新上传视频权限
    "/vod/refreshUploadVideo",
    auth,
    controller.vod.refreshUploadVideo
  );

  // 视频相关
  router.post("/videos", auth, controller.video.createVideo); // 创建视频
  router.get(
    "/videos/:videoId",
    middleware.auth({ requried: false }),
    controller.video.getVideo
  ); // 获取详细视频消息
  router.get("/videos", controller.video.getVideos); // 获取视频列表
  router.get("/users/:userId/videos", controller.video.getUserVideos); // 获取用户发布的视频列表
  router.get("/users/videos/feed", auth, controller.video.getUserFeedVideos); // 获取用户关注的频道视频列表
  router.patch("/videos/:videoId", auth, controller.video.updateVideo); // 更新视频信息
  router.delete("/videos/:videoId", auth, controller.video.deleteVideo); // 删除视频

  // 评论相关
  router.post(
    "/videos/:videoId/comments",
    auth,
    controller.video.createComment
  ); // 添加视频评论
  router.get("/videos/:videoId/comments", controller.video.getVideoComments); // 获取视频评论列表
  router.delete(
    "/videos/:videoId/comments/:commentId",
    auth,
    controller.video.deleteVideoComment
  ); // 删除视频评论

  // 喜欢，不喜欢视频
  router.post("/videos/:videoId/like", auth, controller.video.likeVideo); // 喜欢视频
  router.post("/videos/:videoId/dislike", auth, controller.video.dislikeVideo); // 不喜欢视频
  router.get("/user/videos/liked", auth, controller.video.getUserLikedVideos); // 喜欢视频列表
};
